import vue from "@vitejs/plugin-vue";
import jsx from "@vitejs/plugin-vue-jsx";
import path from "path";
import { wrapperEnv } from "./build/getEnv";
import pkg from "./package.json";
import { defineConfig, loadEnv, ConfigEnv, UserConfig } from "vite";
import { createProxy } from "./build/proxy";
const { dependencies, devDependencies, name, version } = pkg;
import dayjs from "dayjs";
const __APP_INFO__ = {
  pkg: { dependencies, devDependencies, name, version },
  lastBuildTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
};
// https://vitejs.dev/config/
export default defineConfig(({ mode }: ConfigEnv): any => {
  const root = process.cwd();
  const env = loadEnv(mode, root);
  const viteEnv = wrapperEnv(env);
  return {
    plugins: [vue(), jsx()],
    resolve: {
      // 设置路径别名
      alias: {
        "@": path.resolve(__dirname, "src"),
      },
    },
    define: {
      __APP_INFO__: JSON.stringify(__APP_INFO__),
    },
    css: {
      preprocessorOptions: {
        scss: {
          api: "modern",
        },
      },
    },

    server: {
      open: true,
      cors: true,
      // Load proxy configuration from .env.development
      // proxy: {
      //   "/api": {
      //     target: "http://kz.wyshuke.com:80",
      //     // target: "",//打包的
      //     changeOrigin: true,
      //     // rewrite: (a) => a.repl
      proxy: createProxy(viteEnv.VITE_PROXY),
    },
  };
});
